﻿
// 获取当前日期时间
//var now = new Date();
//var year = now.getFullYear();
//var month = ("0" + (now.getMonth() + 1)).slice(-2);
//var day = ("0" + now.getDate()).slice(-2);
//var hours = ("0" + now.getHours()).slice(-2);
//var minutes = ("0" + now.getMinutes()).slice(-2);
////var seconds = ("0" + now.getSeconds()).slice(-2);
//var serialNumber = "PX" + year + month + day + hours + minutes;
//var inputElement = document.getElementById('ProcessNo');
//inputElement.value = serialNumber;
//反填
var obj = {
    "processRouteId": '',
    "processPouteNumber": "",
    "processRouteName": "",
    "state": "",
    "productName": "",
    "createdBy": "",
    "createdDate": "",
    "updatedBy": "",
    "updatedDate": ""

};
$(function () {
    fantian();
    
})
function fantian() {
    // 发送AJAX请求获取数据
    console.log(localStorage.getItem("checkId"))
            $.ajax({
                type: "get",
                url: "/Process/GetFanAllProcess",
                data: {
                    processRouteId: localStorage.getItem("checkId"),
                    token: localStorage.getItem("token")
                },
                success: function (res) {
                    var ter = JSON.parse(res)
                    console.log(ter.data)

                    $(ter.data).each(function () {
                        $('#ProcessNo').val(this.processPouteNumber);
                        $('#ProcessRouteName').val(this.processRouteName);
                        $("[name='State'][value='" + this.state + "']").prop("checked", true)
                   
                        $('#ProductName').val(this.productName);
                        $('#CreatedBy').val(this.createdBy);
                        $('#CreatedDate').val(this.createdDate.substring(0,10));
                        $('#UpdatedBy').val(this.updatedBy);
                        $('#UpdatedDate').val(this.updatedDate);

                        //obj.processRouteId = this.processRouteId
                        //obj.processPouteNumber = this.processPouteNumber
                        //obj.processRouteName = this.processRouteName
                        //obj.state = this.state
                        //obj.productName = this.productName
                        //obj.createdBy = this.createdBy
                        //obj.createdDate = this.createdDate
                        //obj.updatedBy = this.updatedBy
                        //obj.updatedDate = this.updatedDate
                    })
                  
                },
               
            });
         
    
}
//修改工艺信息
var obj1 = {
    "processRouteId": "",
    "processPouteNumber": "",
    "processRouteName": "",
    "state": "",
    "productName": "",
    "createdBy": "",
    "createdDate": "",
    "updatedBy": "",
    "updatedDate": ""

};
layui.use(function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;

    //修改工艺信息
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        var checkStatus = table.checkStatus('allUpdateProcess');
        field.allocationProdutesList = checkStatus.data.map(function (item) {
            return item;
        });
        console.log(field)
        obj1.processRouteId = localStorage.getItem("checkId")
        obj1.processPouteNumber = field.ProcessPouteNumber
        obj1.processRouteName = field.ProcessRouteName
        obj1.state = field.State
        obj1.productName = field.ProductName
        obj1.createdBy = field.CreatedBy
        obj1.createdDate = field.CreatedDate
        obj1.updatedBy = field.UpdatedBy
        obj1.updatedDate = new Date();
        console.log(obj1);//field.products
        // 显示填写结果，仅作演示用
        $.ajax({
            url: '../Process/GetUpdateProcess',
            type: 'post',
            data: {
                field: obj1,
                token: localStorage.getItem("token"),
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(obj1);
                console.log(res);
                if (res.code > 0) {
                    layer.alert("修改成功");
                    location.href = '/Process/ShowProcess'
                } else {
                    layer.alert("修改失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });

});



